< previous page page_159 next page >

Page 159
Select Case
A Select Case statement is used in place of multiple If...Then...ElseIf statements when youre testing the same condition over and over. Your code is more efficient and more readable when you use the Select Case construct than multiple If...Then...ElseIf statements.
Heres the syntax:
9f31265bb40b592b1929e18a47ab28e5.gif
Select Case <Expression>
    Case <Expression List 1>
        <Statement Block 1>
    Case <Expression List 2>
        <Statement Block 1>
    Case Else
        <Statement Block>
End Select
Examples Filename: Employee2.frm
Heres the first example:
9f31265bb40b592b1929e18a47ab28e5.gif
Private Sub cmdSave_Click()
   If txtLast.Text = "" Then
      MsgBox "Last Name Must Be Filled In"
   End If
   If optMale.Value = True Then
      MsgBox "Employee is Male"
   Else 
      MsgBox "Employee is Female"
   End If
   Select Case cboState.Text
      Case "CA"
         MsgBox "Employee can sign up for Health Care"
      Case "AZ"
         MsgBox "Employee is eligible for Bonus Programmer"
      Case "NV"
         MsgBox "Employee is eligible for 401k"
   End Select
End Sub

 
< previous page page_159 next page >

If you like this book, buy it!